//
//  SearchPoiSearchQueryModel.m
//  o_amap
//
//  Created by Q神 on 2021/4/12.
//

#import "SearchPoiSearchQueryModel.h"
#import "MJExtension.h"

@implementation SearchPoiSearchQueryModel

+ (AMapPOIKeywordsSearchRequest *)initSearchKeywordsQuery:(NSString *)query {
    SearchPoiSearchQueryModel *searchQueryModel = [SearchPoiSearchQueryModel mj_objectWithKeyValues:query];
    
    AMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init];
    request.keywords            = searchQueryModel.query;
    request.city                = searchQueryModel.city;
    /*  搜索SDK 3.2.0 中新增加的功能，只搜索本城市的POI。*/
    request.cityLimit           = searchQueryModel.cityLimit;
//    request.requireSubPOIs      = searchQueryModel.requireSubPois;
    return request;
}

+ (AMapPOIAroundSearchRequest *)initSearchAroundQuery:(NSString *)query {
    SearchPoiSearchQueryModel *searchQueryModel = [SearchPoiSearchQueryModel mj_objectWithKeyValues:query];
    
    AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
    if (searchQueryModel.location) {
        request.location            = [AMapGeoPoint locationWithLatitude:[searchQueryModel.location.latitude doubleValue]
                                                               longitude:[searchQueryModel.location.longitude doubleValue]];
    }
    if (searchQueryModel.searchBound.center) {
        request.location            = [AMapGeoPoint locationWithLatitude:[searchQueryModel.searchBound.center.latitude doubleValue]
                                                               longitude:[searchQueryModel.searchBound.center.longitude doubleValue]];
    }
    request.keywords            = searchQueryModel.query;
    request.radius            = searchQueryModel.searchBound.range;
    /* 按照距离排序. */
//    request.sortrule            = searchQueryModel.distanceSort;
//    request.building = searchQueryModel.building;
//    request.city = searchQueryModel.city;
//    request.page = searchQueryModel.pageNum;
//    request.requireSubPOIs = searchQueryModel.requireSubPois;
//    request.requireExtension = searchQueryModel.requireExtension;
    return request;
}

+ (AMapPOIPolygonSearchRequest *)initSearchPoiPolygonQuery:(NSString *)query {
    SearchPoiSearchQueryModel *searchQueryModel = [SearchPoiSearchQueryModel mj_objectWithKeyValues:query];
    
    NSArray *points = [NSArray arrayWithObjects:
                       [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476],
                       [AMapGeoPoint locationWithLatitude:39.890459 longitude:116.581476],
                       nil];
    AMapGeoPolygon *polygon = [AMapGeoPolygon polygonWithPoints:points];
    AMapPOIPolygonSearchRequest *request = [[AMapPOIPolygonSearchRequest alloc] init];
    request.polygon             = polygon;
    request.keywords            = searchQueryModel.query;
//    request.requireExtension    = searchQueryModel.requireExtension;
    return request;
}

@end
